package com.udian.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.udian.dao.UserDao;
import com.udian.dao.UserinfoRepository;
import com.udian.domain.User;
import com.udian.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@Autowired
	private RedisTemplate redisTemplate;


	
	
	@Override
	public User getUser(Long userId) {
		String userJson = stringRedisTemplate.opsForValue().get(String.valueOf(userId));
		User user = null;
		if(userJson==null){
			user = userDao.getUser(userId);
			stringRedisTemplate.opsForValue().set(String.valueOf(userId),JSON.toJSONString(user));
		}
		return user;
	}

	@Override
	public List<User> getUserList(User user) {
		return null;
	}

	@Override
	public User addUser(User user) {
		return userDao.addUser(user);
	}

	@Override
	public User updateUser(User user) {
		return userDao.updateUser(user);
	}

	@Override
	public boolean deleteUser(Long userId) {
		return false;
	}
	
}
